package com.vue.vuedemo.controller;

import com.vue.vuedemo.annotation.CheckToken;
import com.vue.vuedemo.map.LubotuMapper;
import com.vue.vuedemo.pojo.Imglubotu;
import com.vue.vuedemo.pojo.Lubotu;
import com.vue.vuedemo.viewpojo.ResList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
public class LubotuController {

    @Autowired
    LubotuMapper lubotuMapper;

    @CheckToken
    @GetMapping("/getlunbo")
    public ResList getAllLubotu(HttpServletResponse response){
        List<Lubotu> allLuboTu = lubotuMapper.getAllLuboTu();
        response.setHeader("Access-Control-Allow-Origin", "*");
        ResList<Lubotu> resList = new ResList();
        resList.setStatus(0);
        resList.setMessage(allLuboTu);
        
        return resList;
    }

    @CheckToken
    @GetMapping("/getimglubotu/{id}")
    public List<Imglubotu> getimglubotu(HttpServletResponse response, @PathVariable("id") Integer id){
        List<Imglubotu> luboTuByid = lubotuMapper.getLuboTuByid(id);
        response.setHeader("Access-Control-Allow-Origin", "*");
        return luboTuByid;
    }
}
